#include "mycodesetwidget.h"

#include<qDebug>
#include<QLabel>
#include<QSpacerItem>
#include<QHBoxLayout>
#include<QComboBox>
#include<QLineEdit>
#include<QListView>
#include<QPushButton>
#include<QDateTime>
#include<QThread>

#define MYLOG qDebug() << "[" << __FILE__ << ":" << __LINE__ << ":" << QThread::currentThread() << __func__ << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz")<< "]"
MyCodeSetWidget::MyCodeSetWidget(QWidget *parent) :
  QWidget(parent,Qt::WindowStaysOnTopHint)
{

  //创建布局
  create();

  connect(btn1,SIGNAL(clicked()),this,SLOT(btn1Slots()));
}

MyCodeSetWidget::~MyCodeSetWidget()
{
  delete lineEdit;
  lineEdit = nullptr;
  delete btn1;
  btn1 = nullptr;
  delete comboBox;
  comboBox = nullptr;
}
void MyCodeSetWidget::create()
{
  setWindowTitle("编号设置");
  setFixedSize(700,200);

  QLabel *label_old = new QLabel("原编码:",this);

  QLabel *label_new = new QLabel("新编码:",this);

  lineEdit = new QLineEdit("1",this);
  lineEdit->setFixedSize(90,60);

  //  lineEdit->setReadOnly(true);
  lineEdit->setAlignment(Qt::AlignCenter);

  comboBox  = new QComboBox(this);
  comboBox->setFixedSize(110,60);

  QListView* listView1 = new QListView(this);
  comboBox->setView(listView1);
  //按钮美化
  comboBox->setStyleSheet("QComboBox QAbstractItemView::item{height:30px;}");
  comboBox->setFont(QFont(QString::asprintf("Cambria Math"), 18, QFont::Black));

  QStringList strList;
  for(int i = 1;i <= 21;i++ )
    {
      strList.append(QString::number(i));
    }
  comboBox->addItems(strList);

  btn1 = new QPushButton("发送",this);
  btn1->setFixedSize(180,60);

  //弹簧
  QSpacerItem *h_spacer = new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Minimum);

  QHBoxLayout *layout = new QHBoxLayout(this);

  layout->addItem(h_spacer);
  layout->addWidget(label_old);
  layout->addItem(h_spacer);
  layout->addWidget(lineEdit);
  layout->addItem(h_spacer);
  layout->addWidget(label_new);
  layout->addItem(h_spacer);
  layout->addWidget(comboBox);
  layout->addItem(h_spacer);
  layout->addWidget(btn1);
  layout->addItem(h_spacer);
  setLayout(layout);

  setStyleSheet("QLabel,QPushButton,QLineEdit{width: 100px;height: 100px;font-size: 30px;font-bold;font-family: 微软雅黑;}");
}


//发送原新编码
void MyCodeSetWidget::btn1Slots()
{
  QString str = lineEdit->text();

  int yuan = str.toInt();

  int xin = comboBox->currentIndex() + 1;

  emit mySignalCodeSetting(yuan,xin);
}

//得到当前靶位
void MyCodeSetWidget::getIndex(int index)
{
  flag = index;

  lineEdit->setText(QString::number(flag));
}



